-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Port UART reset fix from ESP-IDF #1408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
And probably this one: #1314 |
The above "Port UART reset fix from ESP-IDF #1408 [chemicstry]" fixed my ESP32 issue with corrupt Serial-ports after an “ESP.restart()” – very many thanks! [PS. FYI: I was basically just using “while (Serial2.available()) Serial.write(Serial2.read()); while (Serial.available()) Serial2.write(Serial.read());” to transfer data to & from a GSM-module.] |
@chemicstry will you please make the adjustment that I requested so I can merge this? Thanks :) |
@me-no-dev I do not see any comment where you requested adjustments. Could you repeat? |
I believe there is some missing parts which is needed in case of arduino.
I think disable and enable functions can do that. Something similar should suffice: |
|
@me-no-dev At first I tried using Regarding the interrupts @sysizlayan. When |
@negativekelvin holly cow! I was unaware of this... thanks for pointing out! @chemicstry maybe use some dummy holder for the bytes? uint8_t dummy;
while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
dummy = uart->dev->fifo.rw_byte;
} |
|
||
// we read the data out and make `fifo_len == 0 && rd_addr == wr_addr`. | ||
while(uart->dev->status.rxfifo_cnt != 0 || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) { | ||
READ_PERI_REG(UART_FIFO_REG(uart->num)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use uart->dev->fifo.rw_byte
instead of READ_PERI_REG(UART_FIFO_REG(uart->num))
As @chemicstry said, Serial.flush() behaves differently than expected of the Arduino API, clearing not only the TX buffer but also the RX buffer. Are there any plans to change this? |
uartFlush()
does not work after soft reset due to a hardware bug in ESP32. This was fixed in ESP-IDF by reading out all data from the buffers instead of using reset bits.Using reset bits on UART1 also corrupts data in UART2. From technical reference manual:
Hence UART should only be flushed by reading out.
ESP-IDF commits:
espressif/esp-idf@4052803
espressif/esp-idf@492db05
Fixes: #662